<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 最短无序连续子数组 -->
    <script>
      var findUnsortedSubarray = function (nums) {
        let snums = nums.slice()
        snums.sort((a, b) => a - b)
        let start = nums.length
        let end = 0
        for (let i = 0; i < nums.length; i++) {
          if (snums[i] !== nums[i]) {
            start = Math.min(start, i)
            end = Math.max(end, i)
          }
        }
        return end - start > 0 ? end - start + 1 : 0
      }
      console.log(findUnsortedSubarray([2, 6, 4, 8, 10, 9, 15]))
    </script>
  </body>
</html>
